package cn.z2huo.demo.hello.core.exception;

import org.springframework.util.Assert;

/**
 * <p>
 *
 * @author z2huo
 */
public final class BusinessException extends RuntimeException {

    /**
     * 业务错误码. 默认0000
     */
    private String errorCode = "0000";

    /**
     * 构造方法.
     *
     * @param message 异常消息
     * @param cause   关联异常
     */
    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    /**
     * 构造方法.
     *
     * @param cause 关联异常
     */
    public BusinessException(Throwable cause) {
        super(cause.getMessage(), cause);
    }

    /**
     * 构造方法.
     *
     * @param errorCode 错误码
     */
    public BusinessException(String errorCode) {
//        super(PropertiesUtils.getProperty(String.format("web.message.business.%s", errorCode)));
        Assert.notNull(errorCode,"errorCode can't be null!");
        this.errorCode = errorCode;
    }

    /**
     * 构造方法.
     *
     * @param errorCode 错误码
     * @param message   异常消息
     */
    public BusinessException(String errorCode, String message) {
        super(message);
        Assert.notNull(errorCode,"errorCode can't be null!");
        this.errorCode = errorCode;
    }

    /**
     * 构造方法.
     *
     * @param errorCode     错误码
     * @param messageValues 用于匹配消息模板的值信息
     */
    public BusinessException(String errorCode, String... messageValues) {
//        super(String.format(PropertiesUtils.getProperty(String.format("web.message.business.%s", errorCode)), messageValues));
        Assert.notNull(errorCode,"errorCode can't be null!");
        this.errorCode = errorCode;
    }

    /**
     * 获取错误码.
     *
     * @return 错误码
     */
    public String getErrorCode() {
        return errorCode;
    }

}
